package com.luych.toolbox.data.service.core.mysql;

import com.luych.toolbox.common.enums.DataSourceType;
import com.luych.toolbox.data.service.core.CoreBuilder;
import com.luych.toolbox.data.service.core.CoreDatabase;
import com.luych.toolbox.data.service.core.CoreTable;
import com.luych.toolbox.data.service.core.CoreView;

import java.util.List;
import java.util.stream.Collectors;

public class MysqlDatabase implements CoreDatabase {

    private final String name;
    private final List<MysqlTable> tables;
    private final List<MysqlView> views;

    public MysqlDatabase(CoreDatabase coreDatabase) {
        this.name = coreDatabase.getName();
        this.tables = coreDatabase.getTables().stream()
                .map(table -> (MysqlTable) CoreBuilder.buildTable(DataSourceType.MYSQL, table))
                .collect(Collectors.toList());
        this.views = coreDatabase.getViews().stream()
                .map(view -> (MysqlView) CoreBuilder.buildView(DataSourceType.MYSQL, view))
                .collect(Collectors.toList());
    }

    public MysqlDatabase(String name, List<MysqlTable> tables, List<MysqlView> views) {
        this.name = name;
        this.tables = tables;
        this.views = views;
    }

    @Override
    public DataSourceType getDataSourceType() {
        return DataSourceType.MYSQL;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public List<? extends CoreTable> getTables() {
        return tables;
    }

    @Override
    public List<? extends CoreView> getViews() {
        return views;
    }
}
